import {
  getData,
  postData,
  putData,
  deleteData,
} from "@/api/common/index";

const baseDictInfo = "/api/dict-info";

const DictInfoUrl = {
  listByBelong: "/listByBelong",
  page: "/page",
  url: "",
};

export function getDictInfoPage(params: any, pageNo: number | null | undefined, pageSize : number | null| undefined): Promise<any> {
  let url = baseDictInfo + DictInfoUrl.page + "?pageNum=" + (pageNo ? pageNo : 1) + "&pageSize=" + (pageSize ? pageSize : 10);
  return postData(url, params);
}

export function getDictList(belongTo: string): Promise<any> {
  return getData(baseDictInfo + DictInfoUrl.listByBelong + "?belongTo=" + belongTo);
}

export function getDictInfoDetail(id: number): Promise<any> {
  return getData(baseDictInfo + DictInfoUrl.url + "?id=" + id);
}

export function deleteDictInfo(ids: string) : Promise<any>{
  return deleteData(baseDictInfo + DictInfoUrl.url + "?ids=" + ids);
}

export function addOrEditDictInfo(
  method: string,
  params: any
): Promise<any> {
  if ("put" == method) {
    return putData(baseDictInfo + DictInfoUrl.url, params);
  } else {
    return postData(baseDictInfo +  DictInfoUrl.url, params);
  }
}
